package com.example.singleton;

import java.util.concurrent.locks.AbstractOwnableSynchronizer;

/**
 * @Description JDK 版本：JDK1.5 起
 * 是否 Lazy 初始化：是
 * 是否多线程安全：是
 * 实现难度：较复杂
 * 描述：这种方式采用双锁机制，安全且在多线程情况下能保持高性能。
 * getInstance() 的性能对应用程序很关键。
 * @Date 2021/10/25 8:47
 * @Author ZhangJi
 * @Version 1.0
 */
public class DCLSingleObject {

  private volatile static DCLSingleObject singleObject;

  public DCLSingleObject() {
  }

  public static DCLSingleObject getSingleObject(){

    if (singleObject == null) {
      synchronized (DCLSingleObject.class){
        if (singleObject == null) {
          singleObject = new DCLSingleObject();
        }
      }
    }
    return singleObject;

  }

  public void showMessage(){
    System.out.println("Hello World, DCLSingleObject");
  }

}
